import React from 'react'
import axios from 'axios'

export default function App() {

  const handleClick = async () => {
    // axios({
    //   url: 'https://api.github.com/search/repositories', // q=v&sort=stars
    //   // method: 'GET',
    //   params: {
    //     q: 're',
    //     sort: 'stars'
    //   }
    // })

    /* 
    axios.get('https://api.github.com/search/repositories', {
      params: {q: 're', sort: 'stars'}
    }).then(response => {
      console.log(response.data)
    }) */
    try {
      const response = await axios.get('https://api.github.com/search/repositories', {
        params: {q: 're', sort: 'stars'}
      })
      console.log(response.data)
    } catch (error) {
      alert(error.message)
    }
  }

  return (
    <div>
      <button onClick={handleClick}>请求获取数据</button>
    </div>
  )
}
